package summary.uesr;

import java.util.Scanner;

/**
 * @Author admin
 * @Date 2019/4/16 14:11
 */
public class UserTest {
    static Scanner scannerInt=new Scanner(System.in);
    static Scanner scannerString=new Scanner(System.in);
    static UserDao dao=new UserDaoSet();
    public static void main(String[] args) {
        while (true){
            System.out.println("----欢迎光临----");
            System.out.println("1.注册");
            System.out.println("2.登陆");
            System.out.println("3.退出");
            System.out.println("请输入你的选择");
            int choose=scannerInt.nextInt();
            switch (choose){
                case 1:
                    registerUI();
                    break;
                case 2:
                    loginUI();
                    break;
                case 3:
                    System.out.println("退出了");
                    System.exit(0);
            }
        }
    }

    private static void loginUI() {
        System.out.println("----注册界面----");
        System.out.println("请输入用户名");
         String name=scannerString.nextLine();
        System.out.println("请输入密码");
        String password=scannerString.nextLine();
        System.out.println("请输入email");
        String email=scannerString.nextLine();
        User user=new User(name,password,email);
        dao.register(user);
    }

    private static void registerUI() {
        System.out.println("----登陆界面----");
        System.out.println("请输入用户名");
        String name=scannerString.nextLine();
        System.out.println("请输入密码");
        String password=scannerString.nextLine();
        /*调用工具类方法返回完成登录功能         */
        User user=dao.login(name,password);
        if (user==null){
            System.out.println("登录失败");
        }else {
            System.out.println("欢迎"+user.getName());
        }


    }
}
